package com.cty.A_OutOfMemoryError.B_StackOOM;

/**
 * @Auther: cty
 * @Date: 2020/6/26 21:41
 * @Description: 虚拟机栈和本地方法栈溢出——OutOfMemoryError
 * @VM Args: -Xss2m
 * @version: 1.0
 */
public class StackOOM {
    private void dontStop(){
        while(true){
        }
    }

    public void stackLeakByThread(){
        while(true){
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    dontStop();
                }
            });
            thread.start();
        }  // end while
    }  // end stackLeakByThread()

    public static void main(String[] args) {
        StackOOM oom = new StackOOM();
        oom.stackLeakByThread();
    }  // end main()

}  // end StackOOM{}

/**
 * Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
 * 	at java.lang.Thread.start0(Native Method)
 * 	at java.lang.Thread.start(Thread.java:714)
 * 	at com.cty.OutOfMemoryError.B_StackOOM.StackOOM.stackLeakByThread(StackOOM.java:24)
 * 	at com.cty.OutOfMemoryError.B_StackOOM.StackOOM.main(StackOOM.java:30)
 */
